package com.icloud.article.boot.controller.app;


import com.icloud.article.boot.dto.DiscussDto;
import com.icloud.article.boot.query.DiscussQuery;
import com.icloud.article.boot.service.DiscussService;
import com.icloud.article.boot.vo.DiscussVo;
import com.icloud.common.core.api.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "App评论接口")
@RequestMapping("/app/discuss")
@RequiredArgsConstructor
public class AppDiscussController {

    private final DiscussService discussService;

    @ApiOperation("评论")
    @PutMapping()
    public CommonResult<Void> discuss(@Validated @RequestBody DiscussDto dto){
        discussService.discuss(dto);
        return CommonResult.success();
    }

    @ApiOperation("删除评论")
    @DeleteMapping("/delete/{id}")
    public CommonResult<Void> delete(@ApiParam("评论id") @PathVariable("id") Long id){
        discussService.delete(id);
        return CommonResult.success();
    }

    @ApiOperation("分页查询评论")
    @PostMapping("/page")
    public CommonResult<List<DiscussVo>> page(@Validated @RequestBody DiscussQuery query){
        return CommonResult.success(discussService.list(query));
    }
}
